from urllib.request import urlopen

url = 'http://www.baidu.com/'
response = urlopen(url)
# print(response.read()) #比特
with open('baidu.html', 'w',  encoding='utf-8') as f:
    f.write(response.read().decode('utf-8')) #读取到的网页源代码